import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Text_Collections {
    public static void main(String[] args) {
        Student s1 = new Student("张三",99);
        Student s2 = new Student("李四",33);
        Student s3 = new Student("王五",21);

        List<Student> list = new ArrayList<>();
        Collections.addAll(list,s1,s2,s3);
        //自定义，根据年龄进行排序
/*        Collections.sort(list, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge()- o2.getAge();
            }
        });
        System.out.println(list);*/
        Collections.sort(list);
        System.out.println(list);
    }
}
/*    public static void main(String[] args) {
        String s1 = "李四";
        String s2 = "张三";
        String s3 = "王五";
        String s4 = "张麻子";
        List<String> list = new ArrayList<>();

        //1. addAll() 为集合批量添加数据
        Collections.addAll(list,s1,s2,s3,s4);
        System.out.println(list);
        //输出结果为：[李四, 张三, 王五, 张麻子]

        //2. shuffle() 打乱list集合中的元素顺序
        Collections.shuffle(list);
        System.out.println(list);
        //输出结果为：[王五, 张麻子, 李四, 张三]

        //3. sort() 对list集合的元素进行升序排序
        Collections.sort(list);
        System.out.println(list);
        //输出结果为：[张三, 张麻子, 李四, 王五]

    }
}*/
